﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace hse_2013_test_dima_sasha
{
    public partial class Results : Form
    {
        public Results(Form2 sender)
        {
            InitializeComponent();
            f2 = sender;
        }

        private Form2 f2;
        private void button1_Click(object sender, EventArgs e)
        {
            Close();
            f2.DoShowMistakes();
        }

        private void Results_Load(object sender, EventArgs e)
        {
            int score = Data.NewTrainee.GetScore();
            int total = score + Data.NewTrainee.GetWrong().Count();
            double result = (score * 100 / total);
            label1.Text += String.Format("\n{0}%\n{1}/{2}", result, score, total);
            try
            {
                var fs = new FileStream(".../.../results-engl.txt", FileMode.Open);
                fs.Flush();
                fs.Close();
                fs = new FileStream(".../.../results-econ.txt", FileMode.Open);
                fs.Flush();
                fs.Close();

            }
            catch (Exception)
            {
                var fs = new FileStream(".../.../results-engl.txt", FileMode.Create);
                fs.Flush();
                fs.Close();
                fs = new FileStream(".../.../results-econ.txt", FileMode.Create);
                fs.Flush();
                fs.Close();
            }
            if (Data.SubjectID == 1)
            {
                
                var sw = new StreamWriter(".../.../results-engl.txt", true, Encoding.Default);
                sw.WriteLine(Data.NewTrainee.GetName() + ',' + result + ',' + score + ',' + total);
                sw.Close();
            }
            if (Data.SubjectID == 2)
            {
                var sw = new StreamWriter(".../.../results-econ.txt", true, Encoding.Default);
                sw.WriteLine(Data.NewTrainee.GetName() + ',' + result + ',' + score + ',' + total);
                sw.Close();
            }
        }
    }
}
